from __future__ import annotations

class AbstractError(Exception):
    def __init__(self, msg: str):
        self.__msg = msg

    def msg(self) -> str:
        return self.__msg


class InvalidArgumentError(AbstractError):
    @staticmethod
    def no_args(msg: str) -> InvalidArgumentError:
        return InvalidArgumentError(msg, -1)

    def __init__(self, msg: str = "", index: int = 0):
        super().__init__(msg)
        self. __index = index

    def index(self) -> int:
        return self.__index

    def __repr__(self) -> str:
        if self.__index > -1:
            return f"args({self.__index}) error:{self.msg()}"
        return f"error:{self.msg()}"

class StdError(AbstractError):
    def __init__(self, code: int, msg: str = ""):
        super().__init__(msg)
        self.__code = code

    def code(self) -> int:
        return self.__code

    def __repr__(self) -> str:
        return f"{self.code()}:{self.msg()}"


class DuplicatedKeyError(AbstractError):
    def __init__(self, msg: str, key: str):
        super().__init__(msg)
        self.__key = key

    def key(self) -> str:
        return self.__key

    def __repr__(self) -> str:
        return f"key:[{self.__key}] is duplicated, msg:{self.msg()}"
